package com.clusterswisdom.horn.servlet;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.clusterswisdom.horn.api.ioc.api.HornConfig;
import com.clusterswisdom.horn.control.NormalRequestProcess;
import com.clusterswisdom.horn.control.ProcessPool;

@WebServlet(name="horn", urlPatterns="*.action")
public class HornServlet extends HttpServlet {

	private static final long serialVersionUID = -276506286418779263L;
	
	private ProcessPool requestPool;
	
	private String contentPath;
	
	public void init(ServletConfig config) throws ServletException {
		String scope = config.getServletContext().getInitParameter("scope");
		HornConfig.getConfig().setScope(scope);
		
		contentPath = config.getServletContext().getContextPath();
		requestPool = new ProcessPool();
	}
	
	public void doGet(HttpServletRequest request, HttpServletResponse response) {
		doPost(request, response);
	}
	
	public void doPost(HttpServletRequest request, HttpServletResponse response) {
//		AsyncContext asyncContext = request.startAsync();
//		asyncContext.setTimeout(60000);
//		requestPool.execute(new RequestProcess(contentPath, asyncContext));
		
		new NormalRequestProcess(contentPath, request, response).run();
	}
}